package cn.fengzhilun.javase.day14.day09;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.Test;

public class WordCounter {
	@Test
	public void test() throws IOException {
		List<String> lines = Files.readAllLines(Paths.get("data/scores.csv"));
		
		Map<String, Integer>stat =new HashMap<>();
		
		for(String line :lines) {
//			System.out.println(line);
			String[] split=line.split("[, ]");
			
			for(String word : split) {
				if(word.length()==0) {
					continue;
				}
				
				if(stat.containsKey(word)) {
					
					stat.put(word, stat.get(word)+1);
				}else {
					stat.put(word, 1);
				}
			}
		}
		
		//System.out.println(stat);
		Entry<String, Integer> max = null;
		for(Entry entry: stat.entrySet()) {
			//System.out.println("key:" + entry.getKey() + "value: " + entry.getValue());
//			if(max == null) {
//				max = entry;
//			} else if (max.getValue() < entry.getValue()) {
//				max = entry;
//			}
		}
	}
}
